home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / JRootPane.java < prev    next >
Text File  |  1998-06-30  |  26KB  |  670 lines

  1. /*
  2.  * @(#)JRootPane.java    1.28 98/06/02
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package com.sun.java.swing;
  15.  
  16. import java.awt.*;
  17. import java.awt.event.*;
  18. import com.sun.java.accessibility.*;
  19. import java.util.Vector;
  20. import java.io.Serializable;
  21.  
  22.  
  23. /** 
  24.  * The fundamental component in the container hierarchy. In the same way that
  25.  * JComponent is fundamental to the JFC/Swing components, JRootPane is fundamental
  26.  * to the JFC/Swing window, frame, and pane containers.
  27.  * However, while other classes use inheritance to take advantage of JComponent's
  28.  * capabilities, the container classes delegate operations to a JRootPane instance.
  29.  * Those containers are the heavyweight containers: JFrame, JDialog, JWindow, and 
  30.  * JApplet, as well as the lightweight container, JInternalFrame.
  31.  * <p>
  32.  * The following image shows these relationships:
  33.  * <p align=center><img src="doc-files/JRootPane-1.gif" HEIGHT=484 WIDTH=629></p>
  34.  * The "heavyweight" components (those that delegate to a peer, or native
  35.  * component on the host system) are shown with a darker, heavier box. The four
  36.  * heavyweight JFC/Swing containers (JFrame, JDialog, JWindow, and JApplet) are 
  37.  * shown in relation to the AWT classes they extend. These four components are the
  38.  * only heavyweight containers in the Swing library. The lightweight container, 
  39.  * JInternalPane, is also shown. All 5 of these JFC/Swing containers implement the
  40.  * RootPaneContainer interface, and they all delegate their operations to a 
  41.  * JRootPane (shown with a little "handle" on top).
  42.  * <blockquote>
  43.  * <b>Note:</b> The JComponent method <code>getRootPane</code> can be used to
  44.  * obtain the JRootPane that contains a given component.  
  45.  * </blockquote>
  46.  * <table align="right" border="0">
  47.  * <tr>
  48.  * <td align="center">
  49.  * <img src="doc-files/JRootPane-2.gif" HEIGHT=386 WIDTH=349>
  50.  * </td>
  51.  * </tr>
  52.  * </table>
  53.  * The diagram at right shows the structure of a JRootPane.
  54.  * A JRootpane is made up of a glassPane, an optional menuBar, and
  55.  * a contentPane. (The JLayeredPane manages the menuBar and the contentPane.)
  56.  * The glassPane sits over the top of everything, where it is in a position
  57.  * to intercept mouse movements. Since the glassPane (like the contentPane)
  58.  * can be an arbitrary component, it is also possible to set up the 
  59.  * glassPane for drawing. Lines and images on the glassPane can then range
  60.  * over the frames underneath without being limited by their boundaries. 
  61.  * <p>
  62.  * Although the menuBar component is optional, the layeredPane, contentPane,
  63.  * and glassPane always exist. Attempting to set them to null generates an
  64.  * exception. 
  65.  * <p>
  66.  * The <code>contentPane</code> must be the parent of any children of 
  67.  * the JRootPane. Rather than adding directly to a JRootPane, like this:
  68.  * <PRE>
  69.  *       rootPane.add(child);
  70.  * </PRE>
  71.  * You instead add to the contentPane of the JRootPane, like this:
  72.  * <PRE>
  73.  *       rootPane.getContentPane().add(child);
  74.  * </PRE>
  75.  * The same priniciple holds true for setting layout managers, removing 
  76.  * components, listing children, etc. All these methods are invoked on  
  77.  * the <code>contentPane</code> instead of on the JRootPane.
  78.  * <blockquote>
  79.  * <b>Note:</b> The default layout manager for the <code>contentPane</code> is
  80.  *  a BorderLayout manager. However, the JRootPane uses a custom LayoutManager.
  81.  *  So, when you want to change the layout manager for the components you added
  82.  *  to a JRootPane, be sure to use code like this:<PRE>
  83.  *    rootPane.getContentPane().setLayout(new BoxLayout());
  84.  * </PRE></blockquote>
  85.  * If a JMenuBar component is set on the JRootPane, it is positioned 
  86.  * along the upper edge of the frame. The <code>contentPane</code> is
  87.  * adjusted in location and size to fill the remaining area. 
  88.  * (The JMenuBar and the <code>contentPane</code> are added to the 
  89.  * <code>layeredPane</code> component at the JLayeredPane.FRAME_CONTENT_LAYER 
  90.  * layer.) 
  91.  * <p>
  92.  * The <code>layeredPane</code> is the parent of all children in the JRootPane.
  93.  * It is an instance of JLayeredPane, which provides the ability to add components 
  94.  * at several layers. This capability is very useful when working with menu popups,
  95.  * dialog boxes, and dragging -- situations in which you need to place a component
  96.  * on top of all other components in the pane.
  97.  * <p>
  98.  * The <code>glassPane</code> sits on top of all other components in the JRootPane.
  99.  * That provides a convenient place to draw above all other components, and makes
  100.  * it possible to intercept mouse events, which is useful both for dragging and
  101.  * for drawing. Developers can use <code>setVisible</code> on the glassPane
  102.  * to control when the <code>glassPane</code> displays over the other children. 
  103.  * By default the <code>glassPane</code> is not visible. 
  104.  * <p>
  105.  * The custom LayoutManager used by JRootPane ensures that:
  106.  * <OL>
  107.  * <LI>The <code>glassPane</code>, if present, fills the entire viewable
  108.  *     area of the JRootPane (bounds - insets).
  109.  * <LI>The <code>layeredPane</code> fills the entire viewable area of the
  110.  *     JRootPane. (bounds - insets)
  111.  * <LI>The <code>menuBar</code> is positioned at the upper edge of the 
  112.  *     layeredPane().
  113.  * <LI>The <code>contentPane</code> fills the entire viewable area, 
  114.  *     minus the MenuBar, if present.
  115.  * </OL>
  116.  * Any other views in the JRootPane view hierarchy are ignored.
  117.  * <p>
  118.  * If you replace the LayoutManager of the JRootPane, you are responsible for 
  119.  * managing all of these views. So ordinarily you will want to be sure that you
  120.  * change the layout manager for the <code>contentPane</code> rather than 
  121.  * for the JRootPane itself!
  122.  * <p>
  123.  * Warning: serialized objects of this class will not be compatible with
  124.  * future swing releases.  The current serialization support is appropriate
  125.  * for short term storage or RMI between Swing1.0 applications.  It will
  126.  * not be possible to load serialized Swing1.0 objects with future releases
  127.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  128.  * baseline for the serialized form of Swing objects.
  129.  *
  130.  * @see JLayeredPane
  131.  * @see JMenuBar
  132.  * @see JWindow
  133.  * @see JFrame
  134.  * @see JDialog
  135.  * @see JApplet
  136.  * @see JInternalFrame
  137.  * @see JComponent
  138.  * @see BoxLayout
  139.  *
  140.  * @see <a href="http://java.sun.com/products/jfc/swingdoc-archive/mixing.html">
  141.  * Mixing Heavy and Light Components</a>
  142.  *
  143.  * @version 1.28 06/02/98
  144.  * @author David Kloba
  145.  */
  146. /// PENDING(klobad) Who should be opaque in this component?
  147. public class JRootPane extends JComponent implements Accessible {
  148.  
  149.     /** The menu bar. */
  150.     protected JMenuBar menuBar;
  151.  
  152.     /** The content pane. */
  153.     protected Container contentPane;
  154.  
  155.     /** The layered pane that manages the menu bar and content pane. */
  156.     protected JLayeredPane layeredPane;
  157.  
  158.     /**
  159.      * The glass pane that overlays the menu bar and content pane,
  160.      *  so it can intercept mouse movements and such.
  161.      */
  162.     protected Component glassPane;
  163.     /** 
  164.      * The button that gets activated when the pane has the focus and
  165.      * a UI-specific action like pressing the Enter key occurs.
  166.      */
  167.     protected JButton defaultButton;
  168.     /** The action to take when the defaultButton is pressed.
  169.      *  @see #defaultButton
  170.      */ 
  171.     protected DefaultAction defaultPressAction;   
  172.     /** The action to take when the defaultButton is released.
  173.      *  @see #defaultButton
  174.      */ 
  175.     protected DefaultAction defaultReleaseAction;
  176.  
  177.     /** 
  178.      * Create a JRootPane, setting up its glassPane, LayeredPane, and contentPane.
  179.      */
  180.     public JRootPane() {
  181.         setGlassPane(createGlassPane());
  182.         setLayeredPane(createLayeredPane());
  183.         setContentPane(createContentPane());
  184.         setLayout(createRootLayout());
  185.         setDoubleBuffered(true);
  186.         setBackground(UIManager.getColor("control"));
  187.     }
  188.  
  189.     /** Called by the constructor methods to create the default layeredPane. 
  190.       * Bt default it creates a new JLayeredPane. 
  191.       */
  192.     protected JLayeredPane createLayeredPane() {
  193.         JLayeredPane p = new JLayeredPane();
  194.         p.setName(this.getName()+".layeredPane");
  195.         return p;
  196.     }
  197.  
  198.     /** Called by the constructor methods to create the default contentPane. 
  199.      * By default this method creates a new JComponent add sets a 
  200.      * BorderLayout as its LayoutManager.
  201.      */
  202.     protected Container createContentPane() {
  203.         JComponent c = new JPanel();
  204.         c.setName(this.getName()+".contentPane");
  205.         c.setLayout(new BorderLayout() {
  206.             /* This BorderLayout subclass maps a null constraint to CENTER.
  207.              * Although the reference BorderLayout also does this, some VMs
  208.              * throw an IllegalArgumentException.
  209.              */
  210.             public void addLayoutComponent(Component comp, Object constraints) {
  211.                 if (constraints == null) {
  212.                     constraints = BorderLayout.CENTER;
  213.                 }
  214.                 super.addLayoutComponent(comp, constraints);
  215.             }
  216.         });
  217.         return c;
  218.     }
  219.  
  220.     /** Called by the constructor methods to create the default glassPane. 
  221.       * By default this method creates a new JComponent with visibility 
  222.       * set to false.
  223.       */
  224.     protected Component createGlassPane() {
  225.         JComponent c = new JPanel();
  226.         c.setName(this.getName()+".glassPane");
  227.         c.setVisible(false);
  228.         ((JPanel)c).setOpaque(false);
  229.         return c;
  230.     }
  231.  
  232.     /** Called by the constructor methods to create the default layoutManager. */
  233.     protected LayoutManager createRootLayout() {
  234.         return new RootLayout();
  235.     } 
  236.  
  237.     /** 
  238.      * Adds or changes the menu bar used in the layered pane. 
  239.      * @param menu the JMenuBar to add
  240.      */
  241.     public void setJMenuBar(JMenuBar menu) {
  242.         if(menuBar != null && menuBar.getParent() == layeredPane)
  243.             layeredPane.remove(menuBar);
  244.         menuBar = menu;
  245.  
  246.         if(menuBar != null)
  247.             layeredPane.add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
  248.     }
  249.  
  250.     /**
  251.      * @deprecated As of Swing version 1.0.3
  252.      *  replaced by <code>setJMenuBar(JMenuBar menu)</code>.
  253.      */
  254.     public void setMenuBar(JMenuBar menu){
  255.         if(menuBar != null && menuBar.getParent() == layeredPane)
  256.             layeredPane.remove(menuBar);
  257.         menuBar = menu;
  258.  
  259.         if(menuBar != null)
  260.             layeredPane.add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
  261.     }
  262.     
  263.     /** 
  264.      * Returns the menu bar from the layered pane. 
  265.      * @return the JMenuBar used in the pane
  266.      */
  267.     public JMenuBar getJMenuBar() { return menuBar; }
  268.  
  269.     /**
  270.      * @deprecated As of Swing version 1.0.3
  271.      *  replaced by <code>getJMenubar()</code>.
  272.      */
  273.     public JMenuBar getMenuBar() { return menuBar; }
  274.  
  275.     /** 
  276.      * Sets the content pane -- the container that holds the components
  277.      * parented by the root pane.
  278.      *  
  279.      * @param content the Container to use for component-contents
  280.      * @exception java.awt.IllegalComponentStateException (a runtime
  281.      *            exception) if the content pane parameter is null
  282.      */
  283.     public void setContentPane(Container content) {
  284.         if(content == null)
  285.             throw new IllegalComponentStateException("contentPane cannot be set to null.");
  286.         if(contentPane != null && contentPane.getParent() == layeredPane)
  287.             layeredPane.remove(contentPane);
  288.         contentPane = content;
  289.  
  290.         layeredPane.add(contentPane, JLayeredPane.FRAME_CONTENT_LAYER);
  291.     }
  292.  
  293.     /** 
  294.      * Returns the content pane -- the container that holds the components
  295.      * parented by the root pane.
  296.      *  
  297.      * @return the Container that holds the component-contents
  298.      */
  299.     public Container getContentPane() { return contentPane; }
  300.  
  301. // PENDING(klobad) Should this reparent the contentPane and MenuBar?
  302.     /**
  303.      * Set the layered pane for the root pane. The layered pane
  304.      * typically holds a content pane and an optional JMenuBar.
  305.      *
  306.      * @param layered  the JLayeredPane to use.
  307.      * @exception java.awt.IllegalComponentStateException (a runtime
  308.      *            exception) if the layered pane parameter is null
  309.      */
  310.     public void setLayeredPane(JLayeredPane layered) {
  311.         if(layered == null)
  312.             throw new IllegalComponentStateException("layeredPane cannot be set to null.");
  313.         if(layeredPane != null && layeredPane.getParent() == this)
  314.             this.remove(layeredPane);
  315.         layeredPane = layered;
  316.  
  317.         this.add(layeredPane, -1);
  318.     }
  319.     /**
  320.      * Get the layered pane used by the root pane. The layered pane
  321.      * typically holds a content pane and an optional JMenuBar.
  322.      *
  323.      * @return the JLayeredPane currently in use
  324.      */
  325.     public JLayeredPane getLayeredPane() { return layeredPane; }
  326.  
  327.     /**
  328.      * Sets a specified Component to be the glass pane for this
  329.      * root pane.  The glass pane should normally be a lightweight,
  330.      * transparent component, because it will be made visible when
  331.      * ever the root pane needs to grab input events.  For example,
  332.      * only one JInternalFrame is ever active when using a
  333.      * DefaultDesktop, and any inactive JInternalFrames' glass panes
  334.      * are made visible so that clicking anywhere within an inactive
  335.      * JInternalFrame can activate it.
  336.      * @param glass the Component to use as the glass pane for this
  337.      *              JRootPane.
  338.      */
  339.     public void setGlassPane(Component glass) {
  340.         if (glass == null) {
  341.             throw new NullPointerException("glassPane cannot be set to null.");
  342.         }
  343.  
  344.         boolean visible = false;
  345.         if (glassPane != null && glassPane.getParent() == this) {
  346.             this.remove(glassPane);
  347.             visible = glassPane.isVisible();
  348.         }
  349.  
  350.         glass.setVisible(visible);
  351.         glassPane = glass;
  352.         this.add(glassPane, 0);
  353.         if (visible) {
  354.             repaint();
  355.         }
  356.     }
  357.  
  358.     /**
  359.      * Returns the current glass pane for this JRootPane.
  360.      * @return the current glass pane.
  361.      * @see #setGlassPane
  362.      */
  363.     public Component getGlassPane() { 
  364.         return glassPane; 
  365.     }
  366.  
  367.  
  368.     /**
  369.      * If a descendant of this JRootPane calls revalidate, validate
  370.      * from here on down.
  371.      *<p>
  372.      * Deferred requests to relayout a component and it's descendants,
  373.      * i.e. calls to revalidate(), are pushed upwards to either a JRootPane 
  374.      * or a JScrollPane because both classes override isValidateRoot() to 
  375.      * return true.
  376.      * 
  377.      * @see JComponent#isValidateRoot
  378.      * @return true
  379.      */
  380.     public boolean isValidateRoot() {
  381.     return true;
  382.     }
  383.  
  384.     /**
  385.      * Register ourselves with the SystemEventQueueUtils as a new
  386.      * root pane. 
  387.      * 
  388.      * @see SystemEventQueueUtilities#addRunnableCanvas
  389.      */
  390.     public void addNotify() {
  391.     SystemEventQueueUtilities.addRunnableCanvas(this);
  392.         super.addNotify();
  393.         enableEvents(AWTEvent.KEY_EVENT_MASK);
  394.     }
  395.  
  396.     /**
  397.      * Unregister ourselves from SystemEventQueueUtils.
  398.      * 
  399.      * @see SystemEventQueueUtilities#removeRunnableCanvas
  400.      */
  401.     public void removeNotify() {
  402.     SystemEventQueueUtilities.removeRunnableCanvas(this);
  403.         super.removeNotify();
  404.     }
  405.  
  406.  
  407.     /**
  408.      * Sets the current default button for this JRootPane.
  409.      * The default button is the button which will be activated 
  410.      * when a UI-defined activation event (typically the <Enter> key) 
  411.      * occurs in the RootPane regardless of whether or not the button 
  412.      * has keyboard focus (unless there is another component within 
  413.      * the RootPane which consumes the activation event, such as a JTextPane).
  414.      * For default activation to work, the button must be an enabled
  415.      * descendent of the RootPane when activation occurs.
  416.      * To remove a default button from this RootPane, set this
  417.      * property to null.
  418.      *
  419.      * @see JButton#isDefaultButton 
  420.      * @param default the JButton which is to be the default button
  421.      */
  422.     public void setDefaultButton(JButton defaultButton) { 
  423.         JButton oldDefault = this.defaultButton;
  424.  
  425.         this.defaultButton = defaultButton;
  426.         if (defaultPressAction == null) {
  427.             defaultPressAction = new DefaultAction(this, true);
  428.             defaultReleaseAction = new DefaultAction(this, false);
  429.             // Eventually we should get the KeyStroke from the UI
  430.             // but hardcode it for now....
  431.             registerKeyboardAction(defaultPressAction, 
  432.                                    KeyStroke.getKeyStroke('\n', 0, false), 
  433.                                    JComponent.WHEN_IN_FOCUSED_WINDOW);
  434.             registerKeyboardAction(defaultReleaseAction, 
  435.                                    KeyStroke.getKeyStroke('\n', 0, true), 
  436.                                    JComponent.WHEN_IN_FOCUSED_WINDOW);
  437.         }
  438.         if (oldDefault != defaultButton) {
  439.             defaultPressAction.setOwner(defaultButton);
  440.             defaultReleaseAction.setOwner(defaultButton);
  441.  
  442.             if (oldDefault != null) {
  443.                 oldDefault.repaint();
  444.             }
  445.             if (defaultButton != null) {
  446.                 defaultButton.repaint();
  447.             }
  448.         }
  449.  
  450.         firePropertyChange("defaultButton", oldDefault, defaultButton);        
  451.     }
  452.  
  453.     /**
  454.      * Returns the current default button for this JRootPane.
  455.      * @return the JButton which is currently the default button
  456.      */
  457.     public JButton getDefaultButton() { 
  458.         return defaultButton;
  459.     }
  460.  
  461.     static class DefaultAction extends AbstractAction {
  462.         JButton owner;
  463.         JRootPane root;
  464.         boolean press;
  465.         DefaultAction(JRootPane root, boolean press) {
  466.             super(press? "pressedAction" : "releasedAction");
  467.             this.root = root;
  468.             this.press = press;
  469.         }
  470.         public void setOwner(JButton owner) {
  471.             this.owner = owner;
  472.         }
  473.         public void actionPerformed(ActionEvent e) {
  474.             if (owner != null && SwingUtilities.getRootPane(owner) == root) {
  475.                 ButtonModel model = owner.getModel();
  476.                 if (press) {
  477.                     model.setArmed(true);
  478.                     model.setPressed(true);
  479.                 } else {
  480.                     model.setPressed(false);
  481.                 }
  482.             }
  483.         }
  484.         public boolean isEnabled() {
  485.             return owner.getModel().isEnabled();
  486.         }
  487.     }
  488.  
  489.  
  490.     /** Overridden to enforce the position of the glass component as the zero child. */
  491.     protected void addImpl(Component comp, Object constraints, int index) {
  492.         super.addImpl(comp, constraints, index);
  493.         
  494.         /// We are making sure the glassPane is on top. 
  495.         if(glassPane != null 
  496.             && glassPane.getParent() == this
  497.             && getComponent(0) != glassPane) {
  498.             add(glassPane, 0);
  499.         }
  500.     }
  501.  
  502. ///////////////////////////////////////////////////////////////////////////////
  503. //// Begin Inner Classes
  504. ///////////////////////////////////////////////////////////////////////////////
  505.  
  506.  
  507.     /** 
  508.      * A custom layout manager that is responsible for the layout of 
  509.      * layeredPane, glassPane, and menuBar.
  510.      * <p>
  511.      * Warning: serialized objects of this class will not be compatible with
  512.      * future swing releases.  The current serialization support is appropriate
  513.      * for short term storage or RMI between Swing1.0 applications.  It will
  514.      * not be possible to load serialized Swing1.0 objects with future releases
  515.      * of Swing.  The JDK1.2 release of Swing will be the compatibility
  516.      * baseline for the serialized form of Swing objects.
  517.      */
  518.     protected class RootLayout implements LayoutManager2, Serializable
  519.     {
  520.         /**
  521.          * Returns the amount of space the layout would like to have.
  522.          *
  523.          * @param the Container for which this layout manager is being used
  524.          * @return a Dimension object containing the layout's preferred size
  525.          */ 
  526.         public Dimension preferredLayoutSize(Container parent) {
  527.             Dimension rd, mbd;
  528.             Insets i = getInsets();
  529.         
  530.             if(contentPane != null) {
  531.                 rd = contentPane.getPreferredSize();
  532.             } else {
  533.                 rd = parent.getSize();
  534.             }
  535.             if(menuBar != null) {
  536.                 mbd = menuBar.getPreferredSize();
  537.             } else {
  538.                 mbd = new Dimension(0, 0);
  539.             }
  540.             return new Dimension(Math.max(rd.width, mbd.width) + i.left + i.right, 
  541.                                         rd.height + mbd.height + i.top + i.bottom);
  542.         }
  543.  
  544.         /**
  545.          * Returns the minimum amount of space the layout needs.
  546.          *
  547.          * @param the Container for which this layout manager is being used
  548.          * @return a Dimension object containing the layout's minimum size
  549.          */ 
  550.         public Dimension minimumLayoutSize(Container parent) {
  551.             Dimension rd, mbd;
  552.             Insets i = getInsets();
  553.             if(contentPane != null) {
  554.                 rd = contentPane.getMinimumSize();
  555.             } else {
  556.                 rd = parent.getSize();
  557.             }
  558.             if(menuBar != null) {
  559.                 mbd = menuBar.getMinimumSize();
  560.             } else {
  561.                 mbd = new Dimension(0, 0);
  562.             }
  563.             return new Dimension(Math.max(rd.width, mbd.width) + i.left + i.right, 
  564.                         rd.height + mbd.height + i.top + i.bottom);
  565.         }
  566.  
  567.         /**
  568.          * Returns the maximum amount of space the layout can use.
  569.          *
  570.          * @param the Container for which this layout manager is being used
  571.          * @return a Dimension object containing the layout's maximum size
  572.          */ 
  573.         public Dimension maximumLayoutSize(Container target) {
  574.             Dimension rd, mbd;
  575.             Insets i = getInsets();
  576.             if(menuBar != null) {
  577.                 mbd = menuBar.getMaximumSize();
  578.             } else {
  579.                 mbd = new Dimension(0, 0);
  580.             }
  581.             if(contentPane != null) {
  582.                 rd = contentPane.getMaximumSize();
  583.             } else {
  584.                 // This is silly, but should stop an overflow error
  585.                 rd = new Dimension(Integer.MAX_VALUE, 
  586.                         Integer.MAX_VALUE - i.top - i.bottom - mbd.height - 1);
  587.             }
  588.             return new Dimension(Math.min(rd.width, mbd.width) + i.left + i.right,
  589.                                          rd.height + mbd.height + i.top + i.bottom);
  590.         }
  591.         
  592.         /**
  593.          * Instructs the layout manager to perform the layout for the specified
  594.          * container.
  595.          *
  596.          * @param the Container for which this layout manager is being used
  597.          */ 
  598.         public void layoutContainer(Container parent) {
  599.             Rectangle b = parent.getBounds();
  600.             Insets i = getInsets();
  601.             int contentY = 0;
  602.             int w = b.width - i.right - i.left;
  603.             int h = b.height - i.top - i.bottom;
  604.         
  605.             if(layeredPane != null) {
  606.                 layeredPane.setBounds(i.left, i.top, w, h);
  607.             }
  608.             if(glassPane != null) {
  609.                 glassPane.setBounds(i.left, i.top, w, h);
  610.             }
  611.             // Note: This is laying out the children in the layeredPane,
  612.             // technically, these are not our chilren.
  613.             if(menuBar != null) {
  614.                 Dimension mbd = menuBar.getPreferredSize();
  615.                 menuBar.setBounds(0, 0, w, mbd.height);
  616.                 contentY += mbd.height;
  617.             }
  618.             if(contentPane != null) {
  619.                 contentPane.setBounds(0, contentY, w, h - contentY);
  620.             }
  621.         }
  622.         
  623.         public void addLayoutComponent(String name, Component comp) {}
  624.         public void removeLayoutComponent(Component comp) {}
  625.         public void addLayoutComponent(Component comp, Object constraints) {}
  626.         public float getLayoutAlignmentX(Container target) { return 0.0f; }
  627.         public float getLayoutAlignmentY(Container target) { return 0.0f; }
  628.         public void invalidateLayout(Container target) {}
  629.     }
  630.  
  631. /////////////////
  632. // Accessibility support
  633. ////////////////
  634.  
  635.     /**
  636.      * Get the AccessibleContext associated with this JComponent
  637.      *
  638.      * @return the AccessibleContext of this JComponent
  639.      */
  640.     public AccessibleContext getAccessibleContext() {
  641.         if (accessibleContext == null) {
  642.             accessibleContext = new AccessibleJRootPane();
  643.         }
  644.         return accessibleContext;
  645.     }
  646.  
  647.     /**
  648.      * The class used to obtain the accessible role for this object.
  649.      * <p>
  650.      * Warning: serialized objects of this class will not be compatible with
  651.      * future swing releases.  The current serialization support is appropriate
  652.      * for short term storage or RMI between Swing1.0 applications.  It will
  653.      * not be possible to load serialized Swing1.0 objects with future releases
  654.      * of Swing.  The JDK1.2 release of Swing will be the compatibility
  655.      * baseline for the serialized form of Swing objects.
  656.      */
  657.     protected class AccessibleJRootPane extends AccessibleJComponent {
  658.         /**
  659.          * Get the role of this object.
  660.          *
  661.          * @return an instance of AccessibleRole describing the role of 
  662.          * the object
  663.          */
  664.         public AccessibleRole getAccessibleRole() {
  665.             return AccessibleRole.ROOT_PANE;
  666.         }
  667.     } // inner class AccessibleJRootPane
  668.  
  669. }
  670.